---
id: 655a1479ba7e7c0ee6c1acdd
title: ステップ 12
challengeType: 20
dashedName: step-12
---

# --description--

Now you are going to define an `_insert` method, which is a helper function and does the actual insertion. This method is recursive, meaning it calls itself to traverse the tree until the appropriate location for the new node is found.

Define an `_insert` method with the parameters `self`, `node` and `key`.

# --hints--

You should define an `_insert` method within the `BinarySearchTree` class. Remember to use `pass`.

```js
({ test: () => assert.match(code, /^\s{4}def\s+_insert\s*\([^(]*\)\s*:/m) })
```

Your `_insert` method should take three parameters: `self`, `node` and `key`.

```js
({ test: () => assert.match(code, /^\s{4}def\s+_insert\s*\(\s*self\s*,\s*node\s*,\s*key\s*\)\s*:/m) })
```

# --seed--

## --seed-contents--

```py
class TreeNode:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

class BinarySearchTree:
    def __init__(self):
        self.root = None

    def insert(self,key):
        self.root = self._insert(self.root, key)

--fcc-editable-region--

--fcc-editable-region--
```
